﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BuildingForm
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        Maticsoft.DAL.Kqjl_Info dao = new Maticsoft.DAL.Kqjl_Info();
        private void btnLead_Click(object sender, EventArgs e)
        {
            openFile.Title = "选择文件";
            //openFile.Filter = " xlsx files(*.xlsx)|*.xlsx";
            openFile.FilterIndex = 1;
            openFile.RestoreDirectory = true;
            if (openFile.ShowDialog().Equals(DialogResult.OK))
            {
                DataTable dt = ExcelHelper.RenderDataTableFromExcel(openFile.FileName, 0, 0);
                try
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        Maticsoft.Model.Kqjl_Info kq = new Maticsoft.Model.Kqjl_Info();
                        string name = dr.ItemArray[1].ToString().Trim();
                        string bz = dr.ItemArray[2].ToString().Trim();
                        string date = dr.ItemArray[3].ToString().Trim();
                        string t1 = dr.ItemArray[4].ToString().Trim();
                        string t2 = dr.ItemArray[5].ToString().Trim();
                        string t3 = dr.ItemArray[6].ToString().Trim();
                        string t4 = dr.ItemArray[7].ToString().Trim();
                        string t5 = dr.ItemArray[8].ToString().Trim();
                        string t6 = dr.ItemArray[9].ToString().Trim();
                        kq.xm = name;
                        kq.sfzh = name;
                        kq.qybmm = bz;
                        
                        List<string> list=new List<string> ();
                        list.Add(t1);
                        list.Add(t2);
                        list.Add(t3);
                        list.Add(t4);
                        list.Add(t5);
                        list.Add(t6);
                        foreach (var l in list)
                        {
                            if (!string.IsNullOrEmpty(l))
                            {
                                if (l.Contains("进"))
                                {
                                    string time = l.Replace("(进)", "");
                                    string str = date +" "+ time + ":00";
                                    kq.kqsj = Convert.ToDateTime(str);
                                    kq.jczt = true;
                                }
                                else
                                {
                                    string time = l.Replace("(出)", "");
                                    string str = date + " " + time + ":00";
                                    kq.kqsj = Convert.ToDateTime(str);
                                    kq.jczt = false;
                                }
                                dao.Add(kq);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("文件格式不对！"); return;
                }
            }
        }

       
    }
}
